package com.zerdoor.service.impl;

import com.zerdoor.dao.IEmployArtistTaskDao;
import com.zerdoor.service.ICommonPayService;
import com.zerdoor.service.IEmployArtistTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhongjieyu on 2014/11/3.
 * 项目任务 业务层实现类
 */
@Service
public class EmployArtistTaskServiceImpl implements IEmployArtistTaskService {

    @Autowired
    private IEmployArtistTaskDao employArtistTaskDao;

    @Autowired
    private ICommonPayService commonPayService;

    @Override
    public Map<String, Object> findInitData(int artist_id) throws Exception {

        //查询需求风格
        List<Map<String, String>> styleList = employArtistTaskDao.findMinorCodeByMajorid(103);

        //查询艺术家信息
        Map<String, String> userInfo = employArtistTaskDao.findUserInfoByUserId(artist_id);


        Map<String,Object> dataMap = new HashMap<String, Object>();

        dataMap.put("styleList",styleList);
        dataMap.put("userInfo",userInfo);

        return dataMap;
    }

    @Override
    public void addTaskInfoAndBidinfo(Map<String, String> param) throws Exception {

        //插入任务信息表
        employArtistTaskDao.addTaskInfo(param);

        //插入任务订单表
        employArtistTaskDao.addOrderTask(param);

        //插入竞标信息表
        employArtistTaskDao.addBidinfo(param);

    }

    @Override
    public void updateTaskInfoById(Map<String, String> taskInfo) throws Exception {

        employArtistTaskDao.updateTaskInfoById(taskInfo);
    }

    @Override
    public Map<String, Object> updateFindTaskInfoByTaskId(String taskId) throws Exception {

        //
        Map<String, Object> map = employArtistTaskDao.findTaskInfoByTaskId(taskId);


        float budget = Float.parseFloat(String.valueOf(map.get("budget")));
        //如果金额大于两千则查询支付定金百分比 并且 判断是否需要托管定金
        if(budget > 2000 ){
            map.put("depositScale",commonPayService.findScaleValue( 2 ));
        }else{
            //否则就是百分之百
            map.put("depositScale", "100");
        }

        Map progress = new HashMap();
        progress.put("item_id",taskId);
        progress.put("progress","105102");
        //改变任务状态为发布项目
        employArtistTaskDao.updateCurrentProgressByTaskId(progress);

        return map;
    }




}
